﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Xml;
using WebsiteForWorkFlow.Data;

namespace WebsiteForWorkFlow
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TestApiController : ControllerBase
    {
        DataInstance _dataInstance;
        public TestApiController(DataInstance dataInstance)
        {
            _dataInstance = dataInstance;
        }
        [HttpGet]
        public void GetResult(string jsonStr)
        {
            Dictionary<string, string> dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonStr);
            string id = dict["Id"];

            string result = "false";
            if (id.Equals("test"))
            {
                result = "true";
            }
            else
            {
                result = "false";
            }

            WorkFlowTool.SendOutData(result);
        }

        [HttpGet]
        public void GetNotice(string parameters)
        {
            Dictionary<string, string> getData = JsonConvert.DeserializeObject<Dictionary<string, string>>(parameters);
            string serviceCode = getData["ServiceCode"];
            string detailID = getData["WorkFlowDetailID"];
            DataInstance.AppendMessage("Get Notice:" + serviceCode);
            DataInstance.AppendMessage(parameters);

            // Notify the workFlow
            Dictionary<string, string> sendData = new Dictionary<string, string>();
            sendData["WorkFlowDetailID"] = detailID;
            if (serviceCode == "01")
            {

            }
            sendData.Add("WorkFlowTaskResult", DataInstance.Result);

            WorkFlowTool.TaskIsCompleted(sendData);
        }


        [HttpGet]
        public List<CompanyInfo> GetCompanyInfo()
        {
            List<CompanyInfo> list = new List<CompanyInfo>();
            for (int i = 0; i < 5; i++)
            {
                CompanyInfo companyInfo = new CompanyInfo();
                companyInfo.ID = i.ToString();
                companyInfo.Name = "CompanyName" + i.ToString();
                list.Add(companyInfo);
            }
            return list;
        }


        public class CompanyInfo
        {
            public string ID { get; set; }
            public string Name { get; set; }
        }



    }
}
